/***************************************************************************
 *   Copyright (C) 2007 by Arnold Kraschinski                              *
 *   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 CONTROLLINE_H_
#define CONTROLLINE_H_

#include <QWidget>
#include <QRect>


class QSvgRenderer;
class Kverbos;
class QLearning;

/**
 * This widget uses controlline.ui to make it a
 * usable widget. The widgets contains the controll buttons
 * for the program: Settings, Help, Forward, Menu, Exit
 *
 * @short encapsulates controlline.ui provides the control buttons for the program
 * @author Kraschinski Arnold <arnold.kra67@gmx.de>
 * @version 2.00.00
 */
class ControlLine : public QWidget
{
    Q_OBJECT
public:
    /** The constructor of the class
     */
    ControlLine(QWidget* parent = 0);

    /** Does the painting
     */
    void paintEvent(QPaintEvent *pe);

    /** draw given text in the helper element
      * @param p painter to use to draw
      * @param text text to write to the painter
      */
    void drawHelpText(QPainter &p, const QString &text);

    /** called whenever the window is resized
      * update all svg elements calculated positions based on the new window size
      */
    void resizeEvent(QResizeEvent *);

    /** called when the mouse is moved
      * checks the mouse position against any svg elements that trigger an action
      * or have a hover state, and sets/resets those states
      */
    void mouseMoveEvent(QMouseEvent *e);

    /** called whenever a mouse click occurs
      * checks the mouse position against svg element positions
      * and reacts accordingly
      */
    void mousePressEvent(QMouseEvent *e);

    /** Connects the buttons to the kverbos object.
     */
    void connectButtons(Kverbos* kverbos);
    
    /** Trainer classes need the next button only. */
    void connectNextButton(QLearning* learning);
    
public slots:
    /** The next button might not always have the same function.
      * So the text to display in the widget is different. The text
      * can be set using this function.
      */
    void slotSetNextText(QString text);

signals:
    /** Connect the config button to the slot of kverbos */
    void signalConfig();

    /** Connect the handbook button to the slot of kverbos */
    void signalHandbook();

    /** Connect the about kverbos button to the slot of kverbos */
    void signalAboutApp();

    /** Connect the about KDE button to the slot of kverbos */
    void signalAboutKDE();

    /** Connect the Next button to the slot of kverbos */
    void signalNext();

    /** Connect the Menu button to the slot of kverbos */
    void signalMenu();

    /** Connect the quit button to the slot of kverbos */
    void signalQuit();

private:
    /** sets or clears flag based on whether p is in rect, and set changed if flag changes */
    void CheckRect(const QRect &rect, const QPoint &p, bool &flag, bool &changed);
    
    /** The help text for the next button */
    QString     m_nextText;

    /** renderer used to render gui elements */
    QSvgRenderer * m_renderer;

    /** rectangles to use for detecting hover with the mouse position */
    QRect m_configRect;
    QRect m_helpRect;
    QRect m_nextRect;
    QRect m_menuRect;
    QRect m_quitRect;
    QRect m_handbookRect;
    QRect m_aboutAppRect;
    QRect m_aboutKDERect;

    /** states to use for drawing hover elements, or regular elements */
    bool m_overConfig; 
    bool m_overHelp; 
    bool m_overNext;
    bool m_overMenu; 
    bool m_overQuit; 
    bool m_overHandbook;
    bool m_overAboutApp;
    bool m_overAboutKDE;

    /** ratios to use for drawing elements scaled.
      * based on the current size of the window
      * updated in the resize event and paint event
      */
    double m_xRatio;
    double m_yRatio;

    /** width and height of the .svg graphics
      */
    static const double svgWidth;
    static const double svgHeight;

    /** width and height of the buttons and the ratio
      * between the svg dimensions and the button dimensions
      */
    static const double buttonWidth;
    static const double buttonHeight;
    static const double buttonScaleX;
    static const double buttonScaleY;
    static const double buttonWidth2;
    static const double buttonHeight2;
    static const double buttonScaleX2;
    static const double buttonScaleY2;
    static const double buttonWidth3;
    static const double buttonScaleX3;

    /** positions of the buttons in horizontal and vertical direction
      */
    static const double configPos;
    static const double helpPos;
    static const double nextPos;
    static const double menuPos;
    static const double quitPos;
    static const double handbookPos;
    static const double aboutAppPos;
    static const double aboutKDEPos;

    static const double yPos;
    static const double yPos2;
};



#endif    // CONTROLLINE_H_
