From 81b63588aebee4c45342aebbfbca623957c7adff Mon Sep 17 00:00:00 2001 From: favoritas37 Date: Thu, 16 Jun 2016 01:15:44 +0300 Subject: [PATCH] Use the Image Provider in the encoder. Support static function to register the image provider to the QQuickView. --- src/QZXing.h | 20 ++++++++++++++++---- src/QZXing.pri | 6 ++++-- src/qzxing.cpp | 2 +- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/QZXing.h b/src/QZXing.h index f753669..eaee633 100644 --- a/src/QZXing.h +++ b/src/QZXing.h @@ -9,8 +9,12 @@ #include #elif QT_VERSION >= 0x050000 #include +#include +#include #endif +#include + // forward declaration namespace zxing { class MultiFormatReader; @@ -27,10 +31,10 @@ class ImageHandler; * Regarding DecoderFormat, by default all of those are enabled (except DataMatrix will is still not supported) */ class -#ifndef DISABLE_LIBRARY_FEATURES - QZXINGSHARED_EXPORT -#endif - QZXing : public QObject { + #ifndef DISABLE_LIBRARY_FEATURES + QZXINGSHARED_EXPORT + #endif + QZXing : public QObject { Q_OBJECT Q_ENUMS(DecoderFormat) @@ -75,6 +79,14 @@ public: } #endif +#if QT_VERSION >= 0x050000 + static void registerQMLImageProvider(const QQuickView& view) + { + QQmlEngine *engine = view.engine(); + engine->addImageProvider(QLatin1String("QZXing"), QZXingImageProvider::getInstance()); + } +#endif + void setTryHarder(bool tryHarder); bool getTryHarder(); static QString decoderFormatToString(int fmt); diff --git a/src/QZXing.pri b/src/QZXing.pri index e54f052..415b1d3 100644 --- a/src/QZXing.pri +++ b/src/QZXing.pri @@ -133,7 +133,8 @@ HEADERS += $$PWD/QZXing_global.h \ $$PWD/zxing/zxing/EncodeHint.h \ $$PWD/zxing/zxing/UnsupportedEncodingException.h \ $$PWD/zxing/zxing/common/reedsolomon/ReedSolomonEncoder.h \ - $$PWD/zxing/zxing/common/Types.h + $$PWD/zxing/zxing/common/Types.h \ + $$PWD/QZXingImageProvider.h SOURCES += $$PWD/CameraImageWrapper.cpp \ $$PWD/qzxing.cpp \ @@ -244,7 +245,8 @@ SOURCES += $$PWD/CameraImageWrapper.cpp \ $$PWD/zxing/zxing/qrcode/encoder/MatrixUtil.cpp \ $$PWD/zxing/zxing/qrcode/encoder/QRCode.cpp \ $$PWD/zxing/zxing/EncodeHint.cpp \ - $$PWD/zxing/zxing/common/reedsolomon/ReedSolomonEncoder.cpp + $$PWD/zxing/zxing/common/reedsolomon/ReedSolomonEncoder.cpp \ + $$PWD/QZXingImageProvider.cpp symbian { TARGET.UID3 = 0xE618743C diff --git a/src/qzxing.cpp b/src/qzxing.cpp index 0469b70..3e9f79d 100644 --- a/src/qzxing.cpp +++ b/src/qzxing.cpp @@ -350,7 +350,7 @@ QImage QZXing::encodeData(const QString& data) qRgb(255,255,255)); image = image.scaled(240, 240); - // bool success = image.save("tmp.bmp","BMP"); + QZXingImageProvider::getInstance()->storeImage(image); } catch (std::exception& e) { std::cout << "Error: " << e.what() << std::endl; }