From c92f8f0531f1aa0dfc1cc1de57f6299b2f4868fc Mon Sep 17 00:00:00 2001 From: hooper114 Date: Tue, 19 May 2009 14:04:49 +0000 Subject: [PATCH] Add save to file --- backend_qt4/qzint.cpp | 44 +++++++++++++++++++++++++++++++++++++++++++ backend_qt4/qzint.h | 8 ++++++++ 2 files changed, 52 insertions(+) diff --git a/backend_qt4/qzint.cpp b/backend_qt4/qzint.cpp index 4feb8924..208d0f0d 100644 --- a/backend_qt4/qzint.cpp +++ b/backend_qt4/qzint.cpp @@ -36,6 +36,7 @@ QZint::QZint() m_zintSymbol=0; m_error=0; m_input_mode = UNICODE_MODE; + m_scale = 1.0; } QZint::~QZint() @@ -133,6 +134,16 @@ int QZint::width() return (m_zintSymbol->width+(m_border==BOX)?m_borderWidth*2:0)*(m_zintSymbol->symbology == BARCODE_MAXICODE?(maxi_width+1):1); } +float QZint::scale() +{ + return m_scale; +} + +void QZint::setScale(float scale) +{ + m_scale = scale; +} + QColor QZint::fgColor() { return m_fgColor; @@ -194,6 +205,11 @@ void QZint::setSecurityLevel(int securityLevel) m_securityLevel=securityLevel; } +QString QZint::error_message() +{ + return m_lastError; +} + int QZint::mode() { return m_securityLevel; @@ -203,6 +219,34 @@ void QZint::setMode(int securityLevel) m_securityLevel=securityLevel; } +bool QZint::save_to_file(QString filename) +{ + if (m_zintSymbol) + ZBarcode_Delete(m_zintSymbol); + + m_lastError.clear(); + m_zintSymbol = ZBarcode_Create(); + m_zintSymbol->output_options=m_border; + m_zintSymbol->symbology=m_symbol; + m_zintSymbol->height=m_height; + m_zintSymbol->whitespace_width=m_whitespace; + m_zintSymbol->border_width=m_borderWidth; + m_zintSymbol->option_1=m_securityLevel; + m_zintSymbol->input_mode = m_input_mode; + m_zintSymbol->option_2=m_width; + m_zintSymbol->option_3=m_pdf417CodeWords; + m_zintSymbol->scale=m_scale; + QByteArray bstr=m_text.toAscii(); + QByteArray pstr=m_primaryMessage.left(99).toAscii(); + QByteArray fstr=filename.left(255).toAscii(); + strcpy(m_zintSymbol->primary,pstr.data()); + strcpy(m_zintSymbol->outfile,fstr.data()); + int error = ZBarcode_Encode_and_Print(m_zintSymbol, (unsigned char*)bstr.data()); + if (error > WARN_INVALID_OPTION) + m_lastError=m_zintSymbol->errtxt; + if(error == 0) { return true; } else { return false; } +} + void QZint::render(QPainter & painter, const QRectF & paintRect, AspectRatioMode mode) { encode(); diff --git a/backend_qt4/qzint.h b/backend_qt4/qzint.h index 19a9bea0..130604d9 100644 --- a/backend_qt4/qzint.h +++ b/backend_qt4/qzint.h @@ -69,6 +69,9 @@ public: int securityLevel(); void setSecurityLevel(int securityLevel); + float scale(); + void setScale(float scale); + int mode(); void setMode(int securityLevel); @@ -76,10 +79,14 @@ public: void setWhitespace(int whitespace); + QString error_message(); + void render(QPainter & painter, const QRectF & paintRect, AspectRatioMode mode=IgnoreAspectRatio); const QString & lastError(); bool hasErrors(); + + bool save_to_file(QString filename); private: void encode(); @@ -100,6 +107,7 @@ private: int m_error; int m_whitespace; zint_symbol * m_zintSymbol; + float m_scale; }; } #endif