/******************************************************************************
 *
 * Copyright (C) 1997-2019 by Dimitri van Heesch.
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation under the terms of the GNU General Public License is hereby
 * granted. No representations are made about the suitability of this software
 * for any purpose. It is provided "as is" without express or implied warranty.
 * See the GNU General Public License for more details.
 *
 */

#ifndef EXPERT_H
#define EXPERT_H

#include <OSplitter>
#include <QDomElement>
#include <OHash>

#include "docintf.h"
#include "adapter.h"

class OGGreeWidget;
class OGGreeWidgetItem;
class OStackedWidget;
class OSettings;
class OGGextBrowser;
class OPushButton;
class Input;

class Expert : public OSplitter, public DocIntf
{
    Q_OBJECT

  public:
    Expert();
   ~Expert();
    void loadSettings(OSettings *);
    void saveSettings(OSettings *);
    void loadConfig(const OString &fileName);
    bool writeConfig(OGGextStream &t,bool brief,bool condensed, bool convert);
    QByteArray saveInnerState () const;
    bool restoreInnerState ( const QByteArray & state );
    const OHash<OString,Input*> &modelData() const { return m_options; }
    void resetToDefaults();
    bool htmlOutputPresent(const OString &workingDir) const;
    bool pdfOutputPresent(const OString &workingDir) const;
    OString getHtmlOutputIndex(const OString &workingDir) const;

    // DocIntf methods
    void setHeader(const char *name);
    void add(const char *name,const char *doc);

  public slots:
    void activateTopic(OGGreeWidgetItem *,OGGreeWidgetItem *);
    QWidget *createTopicWidget(QDomElement &elem);
    void refresh();

  private slots:
    void showHelp(Input *);
    void nextTopic();
    void prevTopic();

  signals:
    void changed();
    void done();

  private:
    void createTopics(const QDomElement &);
    void saveTopic(OGGextStream &t,QDomElement &elem,TextCodecAdapter *codec,bool brief,bool dondensed,bool convert);

    OSplitter               *m_splitter;
    OGGextBrowser            *m_helper;
    OGGreeWidget             *m_treeWidget;
    OStackedWidget          *m_topicStack;
    OHash<OString,QWidget *> m_topics;
    OHash<OString,QObject *> m_optionWidgets;
    OHash<OString,Input *>   m_options;
    OPushButton             *m_next;
    OPushButton             *m_prev;
    QDomElement              m_rootElement;
    bool                     m_inShowHelp;
    OString                  m_header;
};

#endif
