#ifndef PQLINEEDIT_H
#define PQLINEEDIT_H

#include <QLineEdit>
#include <QRegExpValidator>
#include "classes/pqwidget.h"

class PQLineEdit;
class PQLineEdit : public QLineEdit {
    Q_OBJECT
    PQ_WIDGET_EX(QLineEdit)

    Q_PROPERTY(QString text READ text WRITE setText)
    Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
    Q_PROPERTY(QString placeholderText READ placeholderText WRITE setPlaceholderText)
    Q_PROPERTY(QString inputMask READ inputMask WRITE setInputMask)
    Q_PROPERTY(QString selectedText READ selectedText)
    Q_PROPERTY(bool clearButtonEnabled READ isClearButtonEnabled WRITE setClearButtonEnabled)

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

    Q_INVOKABLE QString text();
    Q_INVOKABLE bool isReadOnly();
    Q_INVOKABLE QString placeholderText();
    Q_INVOKABLE QString inputMask();
    Q_INVOKABLE QString selectedText();
    Q_INVOKABLE bool isClearButtonEnabled();
    Q_INVOKABLE void setRegExpValidator(const QString &pattern);

public Q_SLOTS:
    Q_INVOKABLE void setText(QString text);
    Q_INVOKABLE void clear();
    Q_INVOKABLE void setReadOnly(bool b);
    Q_INVOKABLE void setPlaceholderText(QString text);
    Q_INVOKABLE void setInputMask(QString mask);
    Q_INVOKABLE void setSelection(int i, int j);
    Q_INVOKABLE void selectAll();
    Q_INVOKABLE void setClearButtonEnabled(bool b);

    void cursorPositionChanged_pslot(int oldPos, int newPos);
    void editingFinished_pslot();
    void returnPressed_pslot();
    void selectionChanged_pslot();
    void textChanged_pslot(const QString &text);
    void textEdited_pslot(const QString &text);

    PQ_ON_SIGNAL_DECL_START
        PQ_ON_SIGNAL(cursorPositionChanged_pslot(int,int));
        PQ_ON_SIGNAL(editingFinished_pslot());
        PQ_ON_SIGNAL(returnPressed_pslot());
        PQ_ON_SIGNAL(selectionChanged_pslot());
        PQ_ON_SIGNAL(textChanged_pslot(string));
        PQ_ON_SIGNAL(textEdited_pslot(string));
        PQWIDGET_ON_SIGNALS();
    PQ_ON_SIGNAL_DECL_END
};

#endif // PQLINEEDIT_H
