/* This file is part of the KDE project
   Copyright (C) 2007 - 2010 Dag Andersen <danders@get2net.dk>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library 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
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#ifndef KPTVIEWLISTDIALOG_H
#define KPTVIEWLISTDIALOG_H

#include "ui_kptviewlistaddview.h"
#include "ui_kptviewlisteditview.h"
#include "ui_kptviewlisteditcategory.h"

#include <KoDialog.h>

#include <QWidget>
#include <QDomDocument>


namespace KPlato
{

class View;
class ViewListWidget;
class ViewListItem;
class AddViewPanel;
class EditViewPanel;
class EditCategoryPanel;
class ViewBase;
class AddReportsViewPanel;

class ViewListDialog : public KoDialog
{
    Q_OBJECT
public:
    ViewListDialog(View *view, ViewListWidget &viewlist, QWidget *parent=0);

protected Q_SLOTS:
    void slotOk();

    void slotViewListItemRemoved(KPlato::ViewListItem *);

Q_SIGNALS:
    void viewCreated(KPlato::ViewBase *view);

private:
    AddViewPanel *m_panel;
};

class AddViewPanel : public QWidget
{
    Q_OBJECT
public:
    AddViewPanel(View *view, ViewListWidget &viewlist, QWidget *parent);

    bool ok();

    Ui::AddViewPanel widget;

Q_SIGNALS:
    void enableButtonOk(bool);
    void viewCreated(KPlato::ViewBase *view);

protected Q_SLOTS:
    void changed();
    void viewtypeChanged(int idx);
    void categoryChanged();
    void fillAfter(KPlato::ViewListItem *cat);

    void viewnameChanged(const QString &text);
    void viewtipChanged(const QString &text);

private:
    View *m_view;
    ViewListWidget &m_viewlist;
    QMap<QString, ViewListItem*> m_categories;
    QStringList m_viewtypes;
    bool m_viewnameChanged;
    bool m_viewtipChanged;
};

class ViewListEditViewDialog : public KoDialog
{
    Q_OBJECT
public:
    ViewListEditViewDialog(ViewListWidget &viewlist, ViewListItem *item, QWidget *parent=0);

protected Q_SLOTS:
    void slotOk();

    void slotViewListItemRemoved(KPlato::ViewListItem*);

private:
    EditViewPanel *m_panel;
};

class EditViewPanel : public QWidget
{
    Q_OBJECT
public:
    EditViewPanel(ViewListWidget &viewlist, ViewListItem *item, QWidget *parent);

    bool ok();

    Ui::EditViewPanel widget;

Q_SIGNALS:
    void enableButtonOk(bool);

protected Q_SLOTS:
    void changed();
    void categoryChanged();
    void fillAfter(KPlato::ViewListItem *cat);

private:
    ViewListItem *m_item;
    ViewListWidget &m_viewlist;
    QMap<QString, ViewListItem*> m_categories;
};

class ViewListEditCategoryDialog : public KoDialog
{
    Q_OBJECT
public:
    ViewListEditCategoryDialog(ViewListWidget &viewlist, ViewListItem *item, QWidget *parent=0);

protected Q_SLOTS:
    void slotOk();

    void slotViewListItemRemoved(KPlato::ViewListItem*);

private:
    EditCategoryPanel *m_panel;
};

class EditCategoryPanel : public QWidget
{
    Q_OBJECT
public:
    EditCategoryPanel(ViewListWidget &viewlist, ViewListItem *item, QWidget *parent);

    bool ok();

    Ui::EditCategoryPanel widget;

Q_SIGNALS:
    void enableButtonOk(bool);

protected Q_SLOTS:
    void changed();
    void fillAfter();

private:
    ViewListItem *m_item;
    ViewListWidget &m_viewlist;
};

#ifdef PLAN_USE_KREPORT
//-------- Reports
class ViewListReportsDialog : public KoDialog
{
    Q_OBJECT
public:
    ViewListReportsDialog(View *view, ViewListWidget &viewlist, const QDomDocument &doc, QWidget *parent=0);

protected Q_SLOTS:
    void slotOk();

    void slotViewListItemRemoved(KPlato::ViewListItem*);

Q_SIGNALS:
    void viewCreated(KPlato::ViewBase *view);

private:
    AddReportsViewPanel *m_panel;
};

class AddReportsViewPanel : public QWidget
{
    Q_OBJECT
public:
    AddReportsViewPanel(View *view, ViewListWidget &viewlist, const QDomDocument &doc, QWidget *parent);

    bool ok();

    Ui::AddViewPanel widget;

Q_SIGNALS:
    void enableButtonOk(bool);
    void viewCreated(KPlato::ViewBase *view);

protected Q_SLOTS:
    void changed();
    void viewtypeChanged(int idx);
    void categoryChanged();
    void fillAfter(KPlato::ViewListItem *cat);

    void viewnameChanged(const QString &text);
    void viewtipChanged(const QString &text);

private:
    View *m_view;
    ViewListWidget &m_viewlist;
    QMap<QString, ViewListItem*> m_categories;
    QStringList m_viewtypes;
    bool m_viewnameChanged;
    bool m_viewtipChanged;
    QDomDocument m_data;
};
#endif

} //KPlato namespace

#endif // CONFIGDIALOG_H
