/***************************************************************************
 *   Copyright (C) 2004 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 QMENU_H
#define QMENU_H

#include <QTreeWidget>

#include <QDomDocument>
#include <QDomNode>
#include <QTreeWidgetItem>

/**
 *  The class gets the munu informatin from an instance of the taskcollection
 *  class.
 *  The menu is displayed in form of a listview.
 * 
 * @short displays the menu as a treeview
 * @author Kraschinski Arnold <arnold.kra67@gmx.de>
 * @version 2.00.00
 */

class QMenu : public QTreeWidget
{
    Q_OBJECT

public:
    QMenu(QWidget *parent = 0);
    ~QMenu();
    /** Test if one of the items in the menu has been selected.
      *
      * @return true means a selection has been made
      */
    bool selected();
    
    /** Get the selected filename. This file is loaded as the new exercise.
      * If there isn't a selection "" is returned
      *
      * @return the selected filename or "" if nothing is selected.
      */
    QString selectedFilename();
    
    /** Get the name of the trainer class that belongs to 
     * this exercise.
     *
     * @return the selected classname or "" if nothing is selected.
      */
    QString selectedClassname();
    
    /** Set the QDomDocument with the menu information. The information comes
      * normally from an instance of the taskcollection class
      */
    void setMenu(QDomDocument* menu);
    
signals:
    /** A Signal that the class QWidgetStack likes to have with the widgets it contains.
     */
    void aboutToShow();

private:    
    /** load the menu out of the menufile and put it into the QListView
     */
    void buildTree( QTreeWidgetItem* parentItem, const QDomNode parentNode );
    
    /** Searche menufile.lang file, this means the menu file for the
     *  language of the user and load the menu.
     */
    QDomDocument* readMenufile( QString file );
    
    /** a helper funciton for appendAdditionalEntry which will be called recursively.
      * It tests if the node add can be sorted into the node menu or its children or
      * if it has to be a sibling of the menu node. 
      * 
      * @param menu a node in the dom-tree of the regular menu
      * @param add a node in the dom-tree with new menu information
      */
    void appendEntry( QDomNode menu, QDomNode add );
     
    /** Besides the standard menu of KVerbos, the user can install additional exercises
      * This exercises come with an additional file which contains a menu entry that
      * has to be placed in the m_menu QDomDocument. The exercises can be installed
      * system wide in $KDEDIR/share/apps/kverbos/exercises or only for one user in
      * the users kde dir.
      */
    void serachAdditionalExercises();
    
    /** The DOM-tree with the menu information.
     */
    QDomDocument*        m_menu;
};

#endif  // QMENU_H
