// ------------------------------------------------------------------------
// NCReport
// Copyright (C) 2018 Helta Ltd
//     Created at: 2018. 10. 01.
//         Author: nszabo
//        Summary: Zint Wrapper Class
//                 This code applies BogDan Vatra's code
// ------------------------------------------------------------------------
#ifndef NCREPORTZINT_H
#define NCREPORTZINT_H

//#include "ncreport_global.h"

#include <QColor>
#include <QPainter>

#ifndef NCREPORT_NO_ZINT
#include "../3rdparty/zintlib/backend/zint.h"
#endif

//#pragma comment( lib, "zint2" )

class NCReportZint
{
public:
    NCReportZint();
    ~NCReportZint();

    enum BorderType { NoBorder=0, BindBorder=2, BoxBorder=4 };
    enum AspectRatioMode { IgnoreAspectRatio=0, KeepAspectRatio=1, CenterBarCode=2 };

    int  symbol() const;
    void setSymbol(int symbol);

    QString text() const;
    void setText(const QString & text);

    QString primaryMessage() const;
    void setPrimaryMessage(const QString & primaryMessage);

    void setHeight(int height);
    int height();

    void setWidth(int width);
    int width();

    void setOption3(int option);

    QColor foreColor() const;
    void setForeColor(const QColor & foreColor);

    QColor backColor() const;
    void setBackColor(const QColor & backColor);

    BorderType borderType() const;
    void setBorderType(BorderType border);

    int borderWidth() const;
    void setBorderWidth(int boderWidth);

    int pdf417CodeWords() const;
    void setPdf417CodeWords(int pdf417CodeWords);

    int securityLevel() const;
    void setSecurityLevel(int securityLevel);

    int getError();

    float scale() const;
    void setScale(float scale);

    void setDotSize(float dot_size);

    int mode() const;
    void setMode(int mode);

    void setInputMode(int input_mode);

    void setWhitespace(int whitespace);
    int whiteSpace() const;

    QString error_message() const;

    void render(QPainter & painter, const QRectF & paintRect, AspectRatioMode mode=IgnoreAspectRatio);

    const QString & lastError() const;
    bool hasErrors();

    bool saveFile(QString filename);

    void setHideText(bool hide);

    void setTargetSize(int width, int height);

private:
    void encode();
    int module_set(int y_coord, int x_coord) const;

private:
    int m_symbol;
    int m_height;
    int m_borderWidth;
    int m_width;
    int m_securityLevel;
    int m_mode;
    int m_pdf417CodeWords;
    int m_inputMode;
    int m_error;
    int m_whiteSpace;
    float m_scale;
    int m_option3;
    bool m_hideText;
    float m_dotSize;
    int targetSizeHorizontal;
    int targetSizeVertical;

#ifndef NCREPORT_NO_ZINT
    zint_symbol * m_zintSymbol;
#endif
    BorderType m_border;
    QColor m_foregroundColor;
    QColor m_backgroundColor;

    QString m_text;
    QString m_primaryMessage;
    QString m_lastError;
};

#endif

