QRCodeReader for iOS

This commit is contained in:
eugenyorbitsoftcom 2022-07-06 14:02:56 +06:00
parent 6744dce57e
commit 9aabe7c72e
7 changed files with 194 additions and 114 deletions

View file

@ -75,7 +75,8 @@ HEADERS += \
logger.h \
loghandler.h \
loglevel.h \
constants.h
constants.h \
platforms/ios/QRCodeReader.h
SOURCES += \
configurators/cloak_configurator.cpp \
@ -126,8 +127,8 @@ SOURCES += \
vpnconnection.cpp \
protocols/vpnprotocol.cpp \
logger.cpp \
loghandler.cpp
loghandler.cpp \
platforms/ios/QRCodeReader.cpp
RESOURCES += \
resources.qrc
@ -296,10 +297,12 @@ ios {
platforms/ios/bigint.h \
platforms/ios/bigintipv6addr.h \
platforms/ios/ipaddress.h \
platforms/ios/ipaddressrange.h \
platforms/ios/QRCodeReader.h
platforms/ios/ipaddressrange.h
SOURCES += \
SOURCES -= \
platforms/ios/QRCodeReader.cpp
SOURCES += \
protocols/ios_vpnprotocol.mm \
platforms/ios/iosnotificationhandler.mm \
platforms/ios/json.cpp \

View file

@ -0,0 +1,14 @@
#include "QRCodeReader.h"
QRCodeReader::QRCodeReader()
{
}
QRect QRCodeReader::cameraSize() {
return QRect();
}
void QRCodeReader::startReading() {}
void QRCodeReader::stopReading() {}
void QRCodeReader::setCameraSize(QRect) {};

View file

@ -157,5 +157,6 @@
<file>images/svg/control_point_black_24dp.svg</file>
<file>images/svg/settings_suggest_black_24dp.svg</file>
<file>ui/qml/Controls/SvgButtonType.qml</file>
<file>ui/qml/Pages/PageQrDecoderIos.qml</file>
</qresource>
</RCC>

View file

@ -24,7 +24,7 @@ enum class Page {Start = 0, NewServer, NewServerProtocols, Vpn,
Wizard, WizardLow, WizardMedium, WizardHigh, WizardVpnMode, ServerConfiguringProgress,
GeneralSettings, AppSettings, NetworkSettings, ServerSettings,
ServerContainers, ServersList, ShareConnection, Sites,
ProtocolSettings, ProtocolShare, QrDecoder, About};
ProtocolSettings, ProtocolShare, QrDecoder, QrDecoderIos, About};
Q_ENUM_NS(Page)
static void declareQmlPageEnum() {

View file

@ -3,7 +3,6 @@ import QtQuick.Controls 2.12
import PageEnum 1.0
import QtMultimedia 5.5
import QZXing 3.2
import QRCodeReader 1.0
import "./"
import "../Controls"
@ -27,7 +26,7 @@ PageBase {
}
Connections {
target: QrDecoderLogic
target: Qt.platform.os != "ios" ? QrDecoderLogic : nil
function onStartDecode() {
console.debug("Starting QR decoder")
loader.sourceComponent = component
@ -53,125 +52,108 @@ PageBase {
Item {
anchors.fill: parent
QRCodeReader {
id: qrCodeReader
onCodeReaded: {
QrDecoderLogic.onDetectedQrCode(code)
Camera
{
id:camera
focus {
focusMode: CameraFocus.FocusContinuous
focusPointMode: CameraFocus.FocusPointAuto
}
Component.onCompleted: {
qrCodeReader.setCameraSize(Qt.rect(loader.x,
loader.y,
loader.width,
loader.height))
qrCodeReader.startReading()
}
Component.onDestruction: qrCodeReader.stopReading()
}
// Camera
// {
// id:camera
// focus {
// focusMode: CameraFocus.FocusContinuous
// focusPointMode: CameraFocus.FocusPointAuto
// }
// }
// VideoOutput
// {
// id: videoOutput
// source: camera
// anchors.top: parent.top
// anchors.bottom: parent.bottom
// anchors.left: parent.left
// anchors.right: parent.right
// autoOrientation: true
// fillMode: VideoOutput.PreserveAspectFit
// filters: [ zxingFilter ]
VideoOutput
{
id: videoOutput
source: camera
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.right: parent.right
autoOrientation: true
fillMode: VideoOutput.PreserveAspectFit
filters: [ zxingFilter ]
// Rectangle {
// color: "black"
// opacity: 0.5
// width: videoOutput.contentRect.width * 0.15
// height: videoOutput.contentRect.height
// x: (videoOutput.width - videoOutput.contentRect.width)/2
// anchors.verticalCenter: videoOutput.verticalCenter
// }
Rectangle {
color: "black"
opacity: 0.5
width: videoOutput.contentRect.width * 0.15
height: videoOutput.contentRect.height
x: (videoOutput.width - videoOutput.contentRect.width)/2
anchors.verticalCenter: videoOutput.verticalCenter
}
// Rectangle {
// color: "black"
// opacity: 0.5
// width: videoOutput.contentRect.width * 0.15
// height: videoOutput.contentRect.height
// x: videoOutput.width/2 + videoOutput.contentRect.width/2 - videoOutput.contentRect.width * 0.15
// anchors.verticalCenter: videoOutput.verticalCenter
// }
Rectangle {
color: "black"
opacity: 0.5
width: videoOutput.contentRect.width * 0.15
height: videoOutput.contentRect.height
x: videoOutput.width/2 + videoOutput.contentRect.width/2 - videoOutput.contentRect.width * 0.15
anchors.verticalCenter: videoOutput.verticalCenter
}
// Rectangle {
// color: "black"
// opacity: 0.5
// width: videoOutput.contentRect.width * 0.7
// height: videoOutput.contentRect.height * 0.15
// x: (videoOutput.width - videoOutput.contentRect.width)/2 + videoOutput.contentRect.width * 0.15
// y: (videoOutput.height - videoOutput.contentRect.height)/2
// }
Rectangle {
color: "black"
opacity: 0.5
width: videoOutput.contentRect.width * 0.7
height: videoOutput.contentRect.height * 0.15
x: (videoOutput.width - videoOutput.contentRect.width)/2 + videoOutput.contentRect.width * 0.15
y: (videoOutput.height - videoOutput.contentRect.height)/2
}
// Rectangle {
// color: "black"
// opacity: 0.5
// width: videoOutput.contentRect.width * 0.7
// height: videoOutput.contentRect.height * 0.15
// x: (videoOutput.width - videoOutput.contentRect.width)/2 + videoOutput.contentRect.width * 0.15
// y: videoOutput.height/2 + videoOutput.contentRect.height/2 - videoOutput.contentRect.height * 0.15
// }
Rectangle {
color: "black"
opacity: 0.5
width: videoOutput.contentRect.width * 0.7
height: videoOutput.contentRect.height * 0.15
x: (videoOutput.width - videoOutput.contentRect.width)/2 + videoOutput.contentRect.width * 0.15
y: videoOutput.height/2 + videoOutput.contentRect.height/2 - videoOutput.contentRect.height * 0.15
}
// LabelType {
// width: parent.width
// text: qsTr("Decoded QR chunks " + QrDecoderLogic.receivedChunksCount + "/" + QrDecoderLogic.totalChunksCount)
// horizontalAlignment: Text.AlignLeft
// visible: QrDecoderLogic.totalChunksCount > 0
// anchors.horizontalCenter: videoOutput.horizontalCenter
// y: videoOutput.height/2 + videoOutput.contentRect.height/2
// }
// }
LabelType {
width: parent.width
text: qsTr("Decoded QR chunks " + QrDecoderLogic.receivedChunksCount + "/" + QrDecoderLogic.totalChunksCount)
horizontalAlignment: Text.AlignLeft
visible: QrDecoderLogic.totalChunksCount > 0
anchors.horizontalCenter: videoOutput.horizontalCenter
y: videoOutput.height/2 + videoOutput.contentRect.height/2
}
}
// QZXingFilter
// {
// id: zxingFilter
// orientation: videoOutput.orientation
// captureRect: {
// // setup bindings
// videoOutput.contentRect;
// videoOutput.sourceRect;
// return videoOutput.mapRectToSource(videoOutput.mapNormalizedRectToItem(Qt.rect(
// 0.15, 0.15, 0.7, 0.7 //0, 0, 1.0, 1.0
// )));
// }
QZXingFilter
{
id: zxingFilter
orientation: videoOutput.orientation
captureRect: {
// setup bindings
videoOutput.contentRect;
videoOutput.sourceRect;
return videoOutput.mapRectToSource(videoOutput.mapNormalizedRectToItem(Qt.rect(
0.15, 0.15, 0.7, 0.7 //0, 0, 1.0, 1.0
)));
}
// decoder {
// enabledDecoders: QZXing.DecoderFormat_QR_CODE
decoder {
enabledDecoders: QZXing.DecoderFormat_QR_CODE
// onTagFound: {
// QrDecoderLogic.onDetectedQrCode(tag)
// }
onTagFound: {
QrDecoderLogic.onDetectedQrCode(tag)
}
// tryHarder: true
// }
tryHarder: true
}
// property int framesDecoded: 0
// property real timePerFrameDecode: 0
property int framesDecoded: 0
property real timePerFrameDecode: 0
// onDecodingFinished:
// {
// timePerFrameDecode = (decodeTime + framesDecoded * timePerFrameDecode) / (framesDecoded + 1);
// framesDecoded++;
// if(succeeded)
// console.log("frame finished: " + succeeded, decodeTime, timePerFrameDecode, framesDecoded);
// }
// }
onDecodingFinished:
{
timePerFrameDecode = (decodeTime + framesDecoded * timePerFrameDecode) / (framesDecoded + 1);
framesDecoded++;
if(succeeded)
console.log("frame finished: " + succeeded, decodeTime, timePerFrameDecode, framesDecoded);
}
}
}

View file

@ -0,0 +1,76 @@
import QtQuick 2.12
import QtQuick.Controls 2.12
import PageEnum 1.0
import QRCodeReader 1.0
import "./"
import "../Controls"
import "../Config"
PageBase {
id: root
page: PageEnum.QrDecoderIos
logic: QrDecoderLogic
onDeactivated: {
console.debug("Stopping QR decoder")
loader.sourceComponent = undefined
}
BackButton {
}
Caption {
id: caption
text: qsTr("Import configuration")
}
Connections {
target: Qt.platform.os == "ios" ? QrDecoderLogic : nil
function onStartDecode() {
console.debug("Starting QR decoder")
loader.sourceComponent = component
}
function onStopDecode() {
console.debug("Stopping QR decoder")
loader.sourceComponent = undefined
}
}
Loader {
id: loader
anchors.top: caption.bottom
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.right: parent.right
}
Component {
id: component
Item {
anchors.fill: parent
QRCodeReader {
id: qrCodeReader
onCodeReaded: {
QrDecoderLogic.onDetectedQrCode(code)
}
Component.onCompleted: {
qrCodeReader.setCameraSize(Qt.rect(loader.x,
loader.y,
loader.width,
loader.height))
qrCodeReader.startReading()
}
Component.onDestruction: qrCodeReader.stopReading()
}
}
}
}

View file

@ -135,7 +135,11 @@ PageBase {
text: qsTr("Scan QR code")
visible: StartPageLogic.pushButtonConnectVisible
onClicked: {
UiLogic.goToPage(PageEnum.QrDecoder)
if (Qt.platform.os == "ios") {
UiLogic.goToPage(PageEnum.QrDecoderIos)
} else {
UiLogic.goToPage(PageEnum.QrDecoder)
}
}
enabled: StartPageLogic.pushButtonConnectEnabled
}