#ifndef PQTREEWIDGET_H
#define PQTREEWIDGET_H

#include "classes/pqwidget.h"
#include <QTreeWidget>

class PQTreeWidget;
class PQTreeWidget : public QTreeWidget {
    Q_OBJECT
    PQ_WIDGET_EX(QTreeWidget)

    Q_PROPERTY( int columnCount READ columnCount WRITE setColumnCount )
    Q_PROPERTY( int currentColumn READ currentColumn )
    Q_PROPERTY( int headerHidden READ headerHidden WRITE setHeaderHidden )
    Q_PROPERTY( int rootIsDecorated READ rootIsDecorated WRITE setRootIsDecorated )
    Q_PROPERTY( int alternatingRowColors READ alternatingRowColors WRITE setAlternatingRowColors )

public:
    Q_INVOKABLE explicit PQTreeWidget(QWidget *parent = 0);
    virtual ~PQTreeWidget();

    Q_INVOKABLE int columnCount();
    Q_INVOKABLE int currentColumn();
    Q_INVOKABLE bool headerHidden();
    Q_INVOKABLE bool alternatingRowColors();

    Q_INVOKABLE int addRootItem(const QStringList &textList, const QStringList &iconList = QStringList());

    Q_INVOKABLE int addItem(int rootItemIndex, const QStringList &textList, const QStringList &iconList = QStringList());
    Q_INVOKABLE bool setItemText(int itemIndex, int column, QString text);
    Q_INVOKABLE bool setItemWidget(int itemIndex, int column, QWidget *widget);

    Q_INVOKABLE void setColumnHidden(int column, bool hidden);
    Q_INVOKABLE void setColumnWidth(int column, int width);

    Q_INVOKABLE void setIconSize(int width, int height);
    Q_INVOKABLE bool setHeaderText(int column, const QString &text);
    Q_INVOKABLE void setHeaderLabels(const QStringList &list);

    Q_INVOKABLE void expandAll();
    Q_INVOKABLE void collapseAll();
    Q_INVOKABLE bool expandItem(int itemIndex);
    Q_INVOKABLE bool collapseItem(int itemIndex);
    Q_INVOKABLE bool isItemExpanded(int itemIndex);

    Q_INVOKABLE bool rootIsDecorated();

    Q_INVOKABLE bool setBackgroundColor(int itemIndex, int column, const QString &color);
    Q_INVOKABLE bool setTextColor(int itemIndex, int column, const QString &color);
    Q_INVOKABLE bool setTextAlignment(int itemIndex, int column, int alignment);
    Q_INVOKABLE bool setFirstItemColumnSpanned(int itemIndex, bool spanned);

Q_SIGNALS:
    void itemDoubleClicked(int itemIndex, int column);
    void itemClicked(int itemIndex, int column);

private slots:
    void itemDoubleClicked_slot(QTreeWidgetItem *item, int column);
    void itemClicked_slot(QTreeWidgetItem *item, int column);

public Q_SLOTS:
    Q_INVOKABLE void clear();
    Q_INVOKABLE void setColumnCount(int columns);
    Q_INVOKABLE void setHeaderHidden(bool hide);
    Q_INVOKABLE void setRootIsDecorated(bool show);
    Q_INVOKABLE void setAlternatingRowColors(bool enable);

    PQ_ON_SIGNAL_DECL_START {
        PQWIDGET_ON_SIGNALS();
    } PQ_ON_SIGNAL_DECL_END

private:
    QMap<int, QTreeWidgetItem*> itemHash;
};

#endif // PQTREEWIDGET_H
