#ifndef PQTABLEWIDGET
#define PQTABLEWIDGET

#include "pqwidget.h"
#include "pqheaderview.h"
#include <QTableWidget>
#include <QHeaderView>

class PQTableWidget;
class PQTableWidget : public QTableWidget {
    Q_OBJECT
    PQ_WIDGET_EX(QTableWidget)

    Q_PROPERTY( int rowCount READ rowCount )
    Q_PROPERTY( int columnCount READ columnCount )
    Q_PROPERTY( int verticalHeaderVisible READ verticalHeaderIsVisible WRITE verticalHeaderSetVisible )
    Q_PROPERTY( int horizontalHeaderVisible READ horizontalHeaderIsVisible WRITE horizontalHeaderSetVisible )

    Q_PROPERTY( QHeaderView* verticalHeader READ verticalHeader WRITE setVerticalHeader )
    Q_PROPERTY( QHeaderView* horizontalHeader READ horizontalHeader WRITE setHorizontalHeader )

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

    Q_INVOKABLE QString horizontalHeaderText(int column);
    Q_INVOKABLE QString verticalHeaderText(int row);
    Q_INVOKABLE QString toolTipAt(int row, int column);
    Q_INVOKABLE QString textAt(int row, int column);
    Q_INVOKABLE int rowCount();
    Q_INVOKABLE int columnCount();
    Q_INVOKABLE bool verticalHeaderIsVisible();
    Q_INVOKABLE void verticalHeaderSetVisible(bool visible);
    Q_INVOKABLE bool horizontalHeaderIsVisible();
    Q_INVOKABLE void horizontalHeaderSetVisible(bool visible);
    Q_INVOKABLE void setCellWidget(int row, int column, QWidget *widget);
    Q_INVOKABLE QWidget* cellWidget(int row, int column);
    Q_INVOKABLE void setColumnWidth(int column, int width);
    Q_INVOKABLE void setRowHeight(int row, int height);
    QTableWidgetItem *pqItemAt(int row, int column);

    Q_INVOKABLE void setVerticalHeader(QHeaderView *verticalHeader);
    Q_INVOKABLE void setHorizontalHeader(QHeaderView *horizontalHeader);
    Q_INVOKABLE QHeaderView *verticalHeader();
    Q_INVOKABLE QHeaderView *horizontalHeader();

public Q_SLOTS:
    Q_INVOKABLE void insertRow(int index);
    Q_INVOKABLE void insertRows(int index, int count);
    Q_INVOKABLE int addRow();
    Q_INVOKABLE void addRows(int count);
    Q_INVOKABLE void insertColumn(int index);
    Q_INVOKABLE void insertColumns(int index, int count);
    Q_INVOKABLE int addColumn();
    Q_INVOKABLE void addColumns(int count);
    Q_INVOKABLE void setTextAt(int row, int column, QString text);
    Q_INVOKABLE void setTextAlignment(int row, int column, int alignment);
    Q_INVOKABLE void setTextColor(int row, int column, QString color);
    Q_INVOKABLE void setBackgroundColor(int row, int column, QString color);
    Q_INVOKABLE void setToolTipAt(int row, int column, QString text);
    Q_INVOKABLE void setHorizontalHeaderText(int column, QString text);
    Q_INVOKABLE void setVerticalHeaderText(int row, QString text);
    Q_INVOKABLE void clear();
    Q_INVOKABLE void clearContents();
    Q_INVOKABLE void setHStretchLastSection(bool stretch);
    Q_INVOKABLE void setVStretchLastSection(bool stretch);

    Q_INVOKABLE void removeRow(int row);
    Q_INVOKABLE void removeColumn(int column);

    void cellActivated_pslot(int row, int column);
    void cellChanged_pslot(int row, int column);
    void cellClicked_pslot(int row, int column);
    void cellDoubleClicked_pslot(int row, int column);
    void cellEntered_pslot(int row, int column);
    void cellPressed_pslot(int row, int column);
    void currentCellChanged_pslot(int currentRow, int currentColumn, int previousRow, int previousColumn);
    /*
    void currentItemChanged_pslot(QTableWidgetItem * current, QTableWidgetItem * previous);
    void itemActivated_pslot(QTableWidgetItem * item);
    void itemChanged_pslot(QTableWidgetItem * item);
    void itemClicked_pslot(QTableWidgetItem * item);
    void itemDoubleClicked_pslot(QTableWidgetItem * item);
    void itemEntered_pslot(QTableWidgetItem * item);
    void itemPressed_pslot(QTableWidgetItem * item);
    */
    void itemSelectionChanged_pslot();

    PQ_ON_SIGNAL_DECL_START {
        PQ_ON_SIGNAL(cellActivated_pslot(int,int));
        PQ_ON_SIGNAL(cellChanged_pslot(int,int));
        PQ_ON_SIGNAL(cellClicked_pslot(int,int));
        PQ_ON_SIGNAL(cellDoubleClicked_pslot(int,int));
        PQ_ON_SIGNAL(cellEntered_pslot(int,int));
        PQ_ON_SIGNAL(cellPressed_pslot(int,int));
        PQ_ON_SIGNAL(currentCellChanged_pslot(int,int,int,int));
        PQ_ON_SIGNAL(itemSelectionChanged_pslot());
        PQWIDGET_ON_SIGNALS();
    } PQ_ON_SIGNAL_DECL_END

};

#endif // PQTABLEWIDGET

