From a7103d5cacd16307e8a52dd7d942df7078f087de Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Tue, 10 Jan 2017 12:01:26 +0100 Subject: [PATCH] Expand QZXingFilter example code - allow autofocus and manual focus - count number of tags matched - allow configuring the barcode scanner from QML --- examples/QZXingLive/QZXingFilter.cpp | 11 ---- examples/QZXingLive/QZXingFilter.h | 4 +- examples/QZXingLive/main.cpp | 1 + examples/QZXingLive/main.qml | 76 ++++++++++++++++++++-------- 4 files changed, 57 insertions(+), 35 deletions(-) diff --git a/examples/QZXingLive/QZXingFilter.cpp b/examples/QZXingLive/QZXingFilter.cpp index afe7ed4..1117cd7 100644 --- a/examples/QZXingLive/QZXingFilter.cpp +++ b/examples/QZXingLive/QZXingFilter.cpp @@ -7,16 +7,11 @@ QZXingFilter::QZXingFilter(QObject *parent) : QAbstractVideoFilter(parent) , decoding(false) { - /// By default all the types are enabled but hence that it is extra processing. - decoder.setDecoder(QZXing::DecoderFormat_Aztec | QZXing::DecoderFormat_QR_CODE); - /// Conecting signals to handlers that will send signals to QML connect(&decoder, &QZXing::decodingStarted, this, &QZXingFilter::handleDecodingStarted); connect(&decoder, &QZXing::decodingFinished, this, &QZXingFilter::handleDecodingFinished); - connect(&decoder, &QZXing::tagFound, - this, &QZXingFilter::handleTagFound); } QZXingFilter::~QZXingFilter() @@ -38,12 +33,6 @@ void QZXingFilter::handleDecodingFinished(bool succeeded) emit isDecodingChanged(); } -void QZXingFilter::handleTagFound(QString tag) -{ -// qDebug() << "handleTagFound"; - emit tagFound(tag); -} - QVideoFilterRunnable * QZXingFilter::createFilterRunnable() { return new QZXingFilterRunnable(this); diff --git a/examples/QZXingLive/QZXingFilter.h b/examples/QZXingLive/QZXingFilter.h index bec42db..2851b48 100644 --- a/examples/QZXingLive/QZXingFilter.h +++ b/examples/QZXingLive/QZXingFilter.h @@ -59,17 +59,16 @@ class QZXingFilter : public QAbstractVideoFilter Q_OBJECT Q_PROPERTY(bool decoding READ isDecoding NOTIFY isDecodingChanged) + Q_PROPERTY(QZXing* decoder READ getDecoder) signals: void isDecodingChanged(); void decodingFinished(bool succeeded, int decodeTime); - void tagFound(QString tag); void decodingStarted(); private slots: void handleDecodingStarted(); void handleDecodingFinished(bool succeeded); - void handleTagFound(QString tag); private: /// Attributes QZXing decoder; @@ -83,6 +82,7 @@ class QZXingFilter : public QAbstractVideoFilter virtual ~QZXingFilter(); bool isDecoding() {return decoding; } + QZXing* getDecoder() { return &decoder; } QVideoFilterRunnable * createFilterRunnable(); diff --git a/examples/QZXingLive/main.cpp b/examples/QZXingLive/main.cpp index 6c75252..03f55da 100644 --- a/examples/QZXingLive/main.cpp +++ b/examples/QZXingLive/main.cpp @@ -21,6 +21,7 @@ int main(int argc, char *argv[]) QQmlApplicationEngine engine; qmlRegisterType("QZXing", 2, 3, "QZXingFilter"); + qmlRegisterType("QZXing", 2, 3, "QZXing"); engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); return app.exec(); diff --git a/examples/QZXingLive/main.qml b/examples/QZXingLive/main.qml index d746299..6d9fcb4 100644 --- a/examples/QZXingLive/main.qml +++ b/examples/QZXingLive/main.qml @@ -1,7 +1,7 @@ import QtQuick 2.5 -import QtQuick.Controls 1.4 +import QtQuick.Window 2.0 +import QtQuick.Controls 2.0 import QtQuick.Layouts 1.1 -import QtQuick.Dialogs 1.2 import QtMultimedia 5.5 import QZXing 2.3 @@ -14,6 +14,9 @@ ApplicationWindow height: 480 title: "Qt QZXing Filter Test" + property int detectedTags: 0 + property string lastTag: "" + Rectangle { id: bgRect @@ -29,12 +32,16 @@ ApplicationWindow anchors.top: parent.top anchors.left: parent.left z: 50 - text: "......" + text: "Tags detected: " + detectedTags } Camera { id:camera + focus { + focusMode: CameraFocus.FocusContinuous + focusPointMode: CameraFocus.FocusPointAuto + } } VideoOutput @@ -45,37 +52,43 @@ ApplicationWindow anchors.bottom: text2.top anchors.left: parent.left anchors.right: parent.right - // autoOrientation: true + autoOrientation: true + fillMode: VideoOutput.PreserveAspectCrop filters: [ zxingFilter ] + MouseArea { + anchors.fill: parent + onClicked: { + camera.focus.customFocusPoint = Qt.point(mouse.x / width, mouse.y / height); + camera.focus.focusMode = CameraFocus.FocusMacro; + camera.focus.focusPointMode = CameraFocus.FocusPointCustom; + } + } } QZXingFilter { id: zxingFilter + decoder { + enabledDecoders: QZXing.DecoderFormat_EAN_13 | QZXing.DecoderFormat_CODE_39 | QZXing.DecoderFormat_QR_CODE + + onTagFound: { + console.log(tag + " | " + decoder.foundedFormat() + " | " + decoder.charSet()); + + window.detectedTags++; + window.lastTag = tag; + } + + tryHarder: true + } onDecodingStarted: { - +// console.log("started"); } onDecodingFinished: { - if(succeeded) - { - - } - else - { - - } - } - - onTagFound: - { - console.log("--!!--"); - console.log(tag); - text1.text = "--00--"; - text2.text = tag; + console.log("frame finished: " + succeeded, decodeTime); } } @@ -87,6 +100,25 @@ ApplicationWindow anchors.bottom: parent.bottom anchors.left: parent.left z: 50 - text: "Nothing yet..." + text: "Last tag: " + lastTag + } + Switch { + text: "Autofocus" + checked: camera.focus.focusMode === CameraFocus.FocusContinuous + anchors { + right: parent.right + bottom: parent.bottom + } + onCheckedChanged: { + if (checked) { + camera.focus.focusMode = CameraFocus.FocusContinuous + camera.focus.focusPointMode = CameraFocus.FocusPointAuto + } else { + camera.focus.focusPointMode = CameraFocus.FocusPointCustom + camera.focus.customFocusPoint = Qt.point(0.5, 0.5) + } + } + font.family: Qt.platform.os === 'android' ? 'Droid Sans Mono' : 'Monospace' + font.pixelSize: Screen.pixelDensity * 5 } }