#ifndef PQLISTWIDGET_H
#define PQLISTWIDGET_H

#include <QListWidget>
#include "pqlistwidgetitem.h"
#include "pqwidget.h"

class PQListWidgetItem;
class PQListWidget;
class PQListWidget : public QListWidget {
    Q_OBJECT
    PQ_WIDGET_EX(QListWidget)

    Q_PROPERTY(bool alternatingRowColors READ alternatingRowColors WRITE setAlternatingRowColors)
    Q_PROPERTY(bool autoScroll READ hasAutoScroll WRITE setAutoScroll)
    Q_PROPERTY(int currentRow READ currentRow WRITE setCurrentRow)

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

    Q_INVOKABLE bool alternatingRowColors();
    Q_INVOKABLE bool hasAutoScroll();
    Q_INVOKABLE int addItem(const QString &label);
    Q_INVOKABLE int addItem(const QString &label, const QString &iconPath);
    Q_INVOKABLE int addItem(PQListWidgetItem *item);
    Q_INVOKABLE QStringList addItems(const QStringList &labels);
    Q_INVOKABLE QString text(int itemIndex) const;
    Q_INVOKABLE bool setText(int itemIndex, const QString &text);
    Q_INVOKABLE void setIconSize(int w, int h);
    Q_INVOKABLE void setItemWidget(QListWidgetItem *item, QWidget *widget);
    Q_INVOKABLE int currentRow();

public Q_SLOTS:
    Q_INVOKABLE void setAlternatingRowColors(bool b);
    Q_INVOKABLE void setAutoScroll(bool b);
    Q_INVOKABLE void setContentsMargins(int left, int top, int right, int bottom);
    Q_INVOKABLE void setCurrentRow(int row);

    void currentItemChanged_pslot(QListWidgetItem *current, QListWidgetItem *previous);
    void currentRowChanged_pslot(int currentRow);
    void currentTextChanged_pslot(const QString &currentText);
    void itemActivated_pslot(QListWidgetItem *item);
    void itemChanged_pslot(QListWidgetItem *item);
    void itemClicked_pslot(QListWidgetItem *item);
    void itemDoubleClicked_pslot(QListWidgetItem *item);
    void itemEntered_pslot(QListWidgetItem *item);
    void itemPressed_pslot(QListWidgetItem *item);
    void itemSelectionChanged();

    PQ_ON_SIGNAL_DECL_START {
        PQ_ON_SIGNAL(currentItemChanged_pslot(QListWidgetItem*,QListWidgetItem*));
        PQ_ON_SIGNAL(currentRowChanged_pslot(int));
        PQ_ON_SIGNAL(currentTextChanged_pslot(string));
        PQ_ON_SIGNAL(itemActivated_pslot(QListWidgetItem*));
        PQ_ON_SIGNAL(itemChanged_pslot(QListWidgetItem*));
        PQ_ON_SIGNAL(itemClicked_pslot(QListWidgetItem*));
        PQ_ON_SIGNAL(itemDoubleClicked_pslot(QListWidgetItem*));
        PQ_ON_SIGNAL(itemEntered_pslot(QListWidgetItem*));
        PQ_ON_SIGNAL(itemPressed_pslot(QListWidgetItem*));
        PQ_ON_SIGNAL(itemSelectionChanged());
        PQWIDGET_ON_SIGNALS();
    } PQ_ON_SIGNAL_DECL_END

private:
    QMap<int, PQListWidgetItem*> itemMap;
};

#endif // PQLISTWIDGET_H
