This commit is contained in:
favoritas37 2017-04-10 16:01:11 +03:00
commit af6833c239
8 changed files with 52 additions and 39 deletions

View File

@ -35,25 +35,27 @@ Project file config tags are now introduced to be able to control the dependenci
The core part requires only "core" and "gui" Qt modules. Though for backward compatibility "quick" Qt module is also required.
The 3 level of dependencies are:
###QZXing with QML (default)
By including QZXing.pri or by building QZXing.pro, apart from the core functionality for C++ it will also include the QML functionality.
### QZXing (core)
By including QZXing.pri or by building QZXing.pro you get the core functionality of QZXing which requires only QtCore and QtGui (because of QImage).
###QZXing (no QML, only core)
If an application is not going to use QML functionality, it is now possible to ditch the dependency to it. This can be done by adding the folloing line to the .pro file of its project:
Warning! The initial default configuration till 20/03/2017 was including qzxing_qml. This tag could not be removed once added, so it was needed to be removed from the defaults.
### QZXing (core + QML)
If an application is going to use QML functionality, it is now possible to add the dependency to it. This can be done by adding the folloing line to the .pro file of its project:
CONFIG -= qzxing_qml
CONFIG += qzxing_qml
###QZXing + QZXingFilter
QZXing includes QZXingFilter, a QAbstractVideoFilter implementation to provide a mean of providing live feed to the decoding library.
### QZXing + QZXingFilter
QZXing includes QZXingFilter, a QAbstractVideoFilter implementation to provide a mean of providing live feed to the decoding library. It automatically includes QML implementation as well.
This option requires "multimedia" Qt module this is why it is considered as a separate configuration. It can be used by adding the folloing line to the .pro file of a project:
CONFIG += qzxing_multimedia
#How to use
# How to use
Follows simple code snippets that brefly show the use of the library. For more details advise the examples included in the repository and the [wiki](https://github.com/ftylitak/qzxing/wiki).
##C++/Qt
## C++/Qt
#include <QZXing.h>
@ -66,7 +68,7 @@ Follows simple code snippets that brefly show the use of the library. For more d
QString result = decoder.decodeImage(imageToDecode);
}
##QML
## QML
First register QZXing type to the QML engine.

View File

@ -1,6 +1,6 @@
QT += qml quick
CONFIG += c++11
CONFIG += c++11 qzxing_qml
SOURCES += main.cpp

View File

@ -5,7 +5,6 @@
#if defined(Q_OS_ANDROID)
#include <QAndroidJniObject>
#include <QtAndroid>
#endif // Q_OS_ANDROID
Application::Application()

View File

@ -2,9 +2,6 @@
#include <QImage>
#include <QPainter>
#include <QDebug>
#include <QQuickItem>
#include <QQuickItemGrabResult>
#include <QQuickWindow>
#include <QThread>
#include <QTime>
@ -13,6 +10,12 @@
#include <QStyleOptionGraphicsItem>
#endif // QT_VERSION < Qt 5.0
#if defined(QZXING_QML)
#include <QQuickItem>
#include <QQuickItemGrabResult>
#include <QQuickWindow>
#endif //QZXING_QML
ImageHandler::ImageHandler(QObject *parent) :
QObject(parent)
{
@ -20,6 +23,8 @@ ImageHandler::ImageHandler(QObject *parent) :
QImage ImageHandler::extractQImage(QObject *imageObj, int offsetX, int offsetY, int width, int height)
{
QImage img;
#if defined(QZXING_QML)
#if QT_VERSION >= 0x050000
QQuickItem *item = qobject_cast<QQuickItem *>(imageObj);
@ -46,7 +51,7 @@ QImage ImageHandler::extractQImage(QObject *imageObj, int offsetX, int offsetY,
qApp->processEvents();
QThread::yieldCurrentThread();
}
QImage img = result->image();
img = result->image();
#else
QGraphicsObject *item = qobject_cast<QGraphicsObject*>(imageObj);
@ -55,12 +60,13 @@ QImage ImageHandler::extractQImage(QObject *imageObj, int offsetX, int offsetY,
return QImage();
}
QImage img(item->boundingRect().size().toSize(), QImage::Format_RGB32);
img = QImage(item->boundingRect().size().toSize(), QImage::Format_RGB32);
img.fill(QColor(255, 255, 255).rgb());
QPainter painter(&img);
QStyleOptionGraphicsItem styleOption;
item->paint(&painter, &styleOption);
#endif
#endif //defined(QZXING_QML)
if (offsetX < 0)
offsetX = 0;

View File

@ -15,11 +15,6 @@
#include <zxing/common/detector/WhiteRectangleDetector.h>
#include <QColor>
#include <QQmlEngine>
#include <QQmlContext>
#include <QQuickImageProvider>
#if QT_VERSION >= 0x040700 && QT_VERSION < 0x050000
#include <QtDeclarative>
#elif QT_VERSION >= 0x050000
@ -31,6 +26,9 @@
#endif //QZXING_MULTIMEDIA
#ifdef QZXING_QML
#include <QQmlEngine>
#include <QQmlContext>
#include <QQuickImageProvider>
#include "QZXingImageProvider.h"
#endif //QZXING_QML
@ -379,6 +377,7 @@ QString QZXing::decodeImage(const QImage &image, int maxWidth, int maxHeight, bo
if (codec)
string = codec->toUnicode(res->getText()->getText().c_str());
}
emit tagFound(string);
emit tagFoundAdvanced(string, foundedFmt, charSet_);
@ -448,6 +447,8 @@ QString QZXing::decodeSubImageQML(const QUrl &imageUrl,
const int offsetX, const int offsetY,
const int width, const int height)
{
#ifdef QZXING_QML
QString imagePath = imageUrl.path();
imagePath = imagePath.trimmed();
QImage img;
@ -471,6 +472,9 @@ QString QZXing::decodeSubImageQML(const QUrl &imageUrl,
if (offsetX || offsetY || width || height)
img = img.copy(offsetX, offsetY, width, height);
return decodeImage(img);
#else
return decodeImage(QImage());
#endif //QZXING_QML
}
QImage QZXing::encodeData(const QString& data)
@ -488,7 +492,9 @@ QImage QZXing::encodeData(const QString& data)
qRgb(255,255,255));
image = image.scaled(240, 240);
#ifdef QZXING_QML
QZXingImageProvider::getInstance()->storeImage(image);
#endif //QZXING_QML
} catch (std::exception& e) {
std::cout << "Error: " << e.what() << std::endl;
}

View File

@ -14,9 +14,7 @@
# limitations under the License.
#
QT += core gui
CONFIG += qzxing_qml
QT += core
DEFINES += QZXING_LIBRARY \
ZXING_ICONV_CONST \
@ -261,7 +259,22 @@ SOURCES += $$PWD/CameraImageWrapper.cpp \
$$PWD/zxing/zxing/EncodeHint.cpp \
$$PWD/zxing/zxing/common/reedsolomon/ReedSolomonEncoder.cpp
qzxing_multimedia {
QT += multimedia
CONFIG += qzxing_qml
DEFINES += QZXING_MULTIMEDIA
HEADERS += \
$$PWD/QZXingFilter.h
SOURCES += \
$$PWD/QZXingFilter.cpp
}
qzxing_qml {
QT += gui
greaterThan(QT_VERSION, 4.7): lessThan(QT_VERSION, 5.0): QT += declarative
greaterThan(QT_MAJOR_VERSION, 4): QT += quick
@ -275,18 +288,6 @@ qzxing_qml {
$$PWD/QZXingImageProvider.cpp
}
qzxing_multimedia {
QT += multimedia
DEFINES += QZXING_MULTIMEDIA
HEADERS += \
$$PWD/QZXingFilter.h
SOURCES += \
$$PWD/QZXingFilter.cpp
}
symbian {
TARGET.UID3 = 0xE618743C
TARGET.EPOCALLOWDLLDATA = 1

View File

@ -64,7 +64,7 @@ void ReedSolomonEncoder::encode(std::vector<int> &toEncode, int ecBytes)
//toEncode.insert(toEncode.begin() + (dataBytes-1) + numZeroCoefficients,
// coefficients.array_->values().begin(),
// coefficients.array_->values().end());
for (size_t i = 0; i < coefficients.count(); i++)
for (size_t i = 0; i < coefficients->size(); i++)
toEncode[dataBytes + numZeroCoefficients + i] = coefficients[i];
}

View File

@ -1,5 +1,4 @@
CONFIG += gnu++11
CONFIG -= qzxing_qml
QMAKE_CXXFLAGS += -std=gnu++11
TARGET = QZXingTests