#ifndef PQPLAINTEXTEDIT_H
#define PQPLAINTEXTEDIT_H

#include <QPlainTextEdit>
#include <QTextFrame>
#include "classes/pqwidget.h"
#include "classes/pqtextcursor.h"

class PQTextCursor;
class PQPlainTextEdit;
class PQPlainTextEdit : public QPlainTextEdit {
    Q_OBJECT
    PQ_WIDGET_EX(QPlainTextEdit)

    Q_PROPERTY( QString plainText READ toPlainText WRITE setPlainText )
    Q_PROPERTY( bool readOnly READ isReadOnly WRITE setReadOnly )

    Q_PROPERTY( int cursorBlockNumber READ cursorBlockNumber )
    Q_PROPERTY( int cursorPosition READ cursorPosition )
    Q_PROPERTY( int cursorPositionInBlock READ cursorPositionInBlock )
    Q_PROPERTY( int textLength READ textLength )
    Q_PROPERTY( QString blockText READ blockText )
    Q_PROPERTY( QString selectedText READ selectedText )

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

    Q_INVOKABLE bool canPaste();
    Q_INVOKABLE int	cursorWidth();
    Q_INVOKABLE QString	documentTitle();
    Q_INVOKABLE void ensureCursorVisible();
    Q_INVOKABLE bool find(QString text, int options = 0);
    Q_INVOKABLE bool findRx(QString exp, int options = 0);
    Q_INVOKABLE bool isReadOnly();
    Q_INVOKABLE bool isUndoRedoEnabled();
    Q_INVOKABLE bool overwriteMode();
    Q_INVOKABLE QString	placeholderText();
    Q_INVOKABLE bool tabChangesFocus();
    Q_INVOKABLE QString toPlainText();
    Q_INVOKABLE int	wordWrapMode();
    Q_INVOKABLE QWidget *viewport();

    Q_INVOKABLE int cursorBlockNumber();
    Q_INVOKABLE int cursorPosition();
    Q_INVOKABLE void setCursorPosition(int pos, int moveMode = 0);
    Q_INVOKABLE int cursorAnchor();
    Q_INVOKABLE int cursorPositionInBlock();
    Q_INVOKABLE bool cursorHasSelection();
    Q_INVOKABLE void cursorBeginEditBlock();
    Q_INVOKABLE void cursorEndEditBlock();
    Q_INVOKABLE int cursorSelectionEnd();
    Q_INVOKABLE int cursorSelectionStart();
    Q_INVOKABLE void cursorMovePosition(int operation, int moveMode = 0, int n = 1);
    Q_INVOKABLE void cursorInsertText(const QString &text);
    Q_INVOKABLE int textLength();

    Q_INVOKABLE QObject *getTextCursor();

    Q_INVOKABLE QString blockText();
    Q_INVOKABLE QString selectedText();

public Q_SLOTS:
    Q_INVOKABLE void append(const QString &text);
    Q_INVOKABLE void clear();
    Q_INVOKABLE void copy();
    Q_INVOKABLE void cut();
    Q_INVOKABLE void insertHtml(QString text);
    Q_INVOKABLE void insertPlainText(QString text);
    Q_INVOKABLE void paste();
    Q_INVOKABLE void redo();
    Q_INVOKABLE void scroll(int dx, int dy);
    Q_INVOKABLE void selectAll();
    Q_INVOKABLE void setPlainText(QString text);
    Q_INVOKABLE void setTabStopWidth(int width);
    Q_INVOKABLE void undo();
    Q_INVOKABLE void zoomIn(int range = 1);
    Q_INVOKABLE void zoomOut(int range = 1);
    Q_INVOKABLE void setCursorWidth(int width);
    Q_INVOKABLE void setDocumentTitle(QString title);
    Q_INVOKABLE void setOverwriteMode(bool overwrite);
    Q_INVOKABLE void setPlaceholderText(QString placeholderText);
    Q_INVOKABLE void setReadOnly(bool ro);
    Q_INVOKABLE void setTabChangesFocus(bool b);
    Q_INVOKABLE void setTextInteractionFlags(int flags);
    Q_INVOKABLE void setUndoRedoEnabled(bool enable);
    Q_INVOKABLE void setWordWrapMode(int policy);

    void blockCountChanged_pslot(int newBlockCount);
    void copyAvailable_pslot(bool yes);
    void cursorPositionChanged_pslot();
    void modificationChanged_pslot(bool changed);
    void redoAvailable_pslot(bool available);
    void selectionChanged_pslot();
    void textChanged_pslot();
    void undoAvailable_pslot(bool available);

    PQ_ON_SIGNAL_DECL_START {
        PQ_ON_SIGNAL(blockCountChanged_pslot(int));
        PQ_ON_SIGNAL(copyAvailable_pslot(bool));
        PQ_ON_SIGNAL(cursorPositionChanged_pslot());
        PQ_ON_SIGNAL(modificationChanged_pslot(bool));
        PQ_ON_SIGNAL(redoAvailable_pslot(bool));
        PQ_ON_SIGNAL(selectionChanged_pslot());
        PQ_ON_SIGNAL(textChanged_pslot());
        PQ_ON_SIGNAL(undoAvailable_pslot(bool));
        PQWIDGET_ON_SIGNALS();
    } PQ_ON_SIGNAL_DECL_END

private:
    PQTextCursor *pq_textCursor;
    QTextCursor m_textCursor;
};
#endif // PQPLAINTEXTEDIT_H
